<template>
    <van-form @submit="handleLogin">
        <van-cell-group inset>
            <van-field
                    v-model="user.username"
                    label="用户名"
                    placeholder="用户名"
                    :rules="[{ required: true, message: '请填写用户名' }]"
            />
            <van-field
                    v-model="user.password"
                    type="password"
                    label="密码"
                    placeholder="密码"
                    :rules="[{ required: true, message: '请填写密码' }]"
            />
        </van-cell-group>
        <div style="margin: 16px;">
            <van-button round block type="primary" native-type="submit">
                登录
            </van-button>
        </div>
    </van-form>

</template>

<script>
import {showDialog} from "vant";
import {showNotify} from "vant";
export default {
    name: "login",
    data(){
        return{
           user:{
               username:'',
               password:''
           },
            redirect:''
        }
    },
    methods:{
        handleLogin(){
            // TODO  加密
            this.$axios.post('/ele_server/user/login',this.user).then(({data:res}) => {
            if(res.status === 0){
                // showDialog({
                // message: res.message});
               showNotify({type:'success',message:res.message});
               this.$router.push(this.redirect)

              }else{
                alert(res.message)

            }
        })
        }

    },created() {
        this.redirect=this.$route.query.redirect ? this.$route.query.redirect :'/business/list';

        }
}
</script>

<style scoped lang="stylus">
</style>
